package com.mtons.mblog.config;

import com.mtons.mblog.modules.rabbitmq.RabbitConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbit配置
 *
 * @author xiaomi
 * @date 2020/05/14
 */
@Configuration
public class RabbitConfig {

    private Logger log = LoggerFactory.getLogger(RabbitConfig.class);

    /**
     * 数据同步es的队列
     *
     * @return {@link Queue}
     */
    @Bean
    public Queue esQueue() {
        return new Queue(RabbitConstant.ES_QUEUE, true, false, false);
    }

    /**
     * 数据同步es的交换机
     *
     * @return {@link DirectExchange}
     */
    @Bean
    public DirectExchange esExchange() {
        return new DirectExchange(RabbitConstant.ES_EXCHAGE, true, false);
    }

    /**
     * 数据同步es的绑定键
     *
     * @return {@link Binding}
     */
    @Bean
    public Binding esBinding() {
        return BindingBuilder.bind(esQueue()).to(esExchange()).with(RabbitConstant.ES_ROUTING_KEY);
    }

    /**
     * 发送邮件的队列
     *
     * @return {@link Queue}
     */
    @Bean
    public Queue emailQueue() {
        return new Queue(RabbitConstant.EMAIL_QUEUE, true, false, false);
    }

    /**
     * 发送邮件的交换机
     *
     * @return {@link DirectExchange}
     */
    @Bean
    public DirectExchange emailExchage() {
        return new DirectExchange(RabbitConstant.EMAIL_EXCHAGE, true, false, null);
    }

    /**
     * 发送邮件的绑定键
     *
     * @return {@link Binding}
     */
    @Bean
    public Binding emailBinding() {
        return BindingBuilder.bind(emailQueue()).to(emailExchage()).with(RabbitConstant.EMAIL_ROUTING_KEY);
    }

    /**
     * 文章操作的队列
     *
     * @return {@link Queue}
     */
    @Bean
    public Queue postQueue() {
        return new Queue(RabbitConstant.POST_QUEUE, true, false, false);
    }

    /**
     * 文章操作的交换机
     *
     * @return {@link DirectExchange}
     */
    @Bean
    public DirectExchange postExchage() {
        return new DirectExchange(RabbitConstant.POST_EXCHAGE, true, false, null);
    }

    /**
     * 文章操作的绑定键
     *
     * @return {@link Binding}
     */
    @Bean
    public Binding postBinding() {
        return BindingBuilder.bind(postQueue()).to(postExchage()).with(RabbitConstant.POST_ROUTING_KEY);
    }

    /**
     * 关注用户的队列
     *
     * @return {@link Queue}
     */
    @Bean
    public Queue followQueue() {
        return new Queue(RabbitConstant.FOLLOW_QUEUE, true, false, false);
    }

    /**
     * 关注用户的交换机
     *
     * @return {@link DirectExchange}
     */
    @Bean
    public DirectExchange followExchage() {
        return new DirectExchange(RabbitConstant.FOLLOW_EXCHAGE, true, false, null);
    }

    /**
     * 关注用户的绑定键
     *
     * @return {@link Binding}
     */
    @Bean
    public Binding followBinding() {
        return BindingBuilder.bind(followQueue()).to(followExchage()).with(RabbitConstant.FOLLOW_ROUTING_KEY);
    }

    /**
     * 文章更新队列
     *
     * @return {@link Queue}
     */
    @Bean
    public Queue postUpdateQueue() {
        return new Queue(RabbitConstant.POST_UPDATE_QUEUE, true, false, false);
    }

    /**
     * 文章更新交换机
     *
     * @return {@link DirectExchange}
     */
    @Bean
    public DirectExchange postUpdateExchange() {
        return new DirectExchange(RabbitConstant.POST_UPDATE_EXCHAGE, true, false, null);
    }

    /**
     * 文章更新绑定键
     *
     * @return {@link Binding}
     */
    @Bean
    public Binding postUpdateBinding() {
        return BindingBuilder.bind(postUpdateQueue()).to(postUpdateExchange()).with(RabbitConstant.POST_UPDATE_ROUTING_KEY);
    }

}